package com.dongdongmovie.controller;

import com.dongdongmovie.pojo.TabSeller;
import com.dongdongmovie.service.TabCategory_Service;
import com.dongdongmovie.service.TabSeller_Service;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("TabSeller")
public class TabSeller_Controller {

    //注入service
    @DubboReference
    private TabSeller_Service tabSeller_service;
    @DubboReference
    private TabCategory_Service tabCategory_service;

    //跳转到首页
    @RequestMapping("tzshow")
    public String tzshow() {
        return "TabSeller/show";
    }

    //跳转到add
    @RequestMapping("tzadd")
    public String tzadd() {
        return "TabSeller/add";
    }

    //跳转到update
    @RequestMapping("tzupdate")
    public String tzupdate(Integer sid, Model m) {
        TabSeller t = tabSeller_service.showbyId(sid);
        m.addAttribute("t",t);
        return "TabSeller/update";
    }

    //跳转到home
    @RequestMapping("tzTabRoute")
    public String tzTabRoute(Integer sid,Model m) {
        m.addAttribute("sid",sid);
        m.addAttribute("TabCategory", tabCategory_service.show());
        return "TabRoute/show";
    }

    //查询数据
    @ResponseBody
    @RequestMapping("show")
    public List<TabSeller> show() {
        return tabSeller_service.show();
    }

    //添加数据
    @ResponseBody
    @RequestMapping("add")
    public int add(TabSeller t) {
        return tabSeller_service.add(t);
    }

    //根据ID修改数据
    @ResponseBody
    @RequestMapping("updatebyId")
    public int updatebyId(TabSeller t) {
        return tabSeller_service.updatebyId(t);
    }

    //根据ID删除数据
    @ResponseBody
    @RequestMapping("deletebyId")
    public int deletebyId(Integer sid) {
        return tabSeller_service.deletebyId(sid);
    }

    //删除已选数据
    @ResponseBody
    @RequestMapping("deleteall")
    public int deleteall(@RequestParam(value = "sids[]") Integer[] sids) {
        return tabSeller_service.deleteall(sids);
    }

}
